export type FallStatus = 'normal' | 'suspected' | 'confirmed';

export class FallService {
  private status: FallStatus = 'normal';
  private subscribers: Array<(s: FallStatus) => void> = [];

  subscribe(cb: (s: FallStatus) => void): () => void {
    this.subscribers.push(cb);
    cb(this.status);
    return () => {
      this.subscribers = this.subscribers.filter(fn => fn !== cb);
    };
  }

  setStatus(s: FallStatus) {
    this.status = s;
    this.subscribers.forEach(fn => fn(s));
  }

  getStatus(): FallStatus {
    return this.status;
  }
}

export const fallService = new FallService();